﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Reborn_WorldServer.PendingClients
{
    public class PendingClientsManager
    {
        private List<PendingClient> pendingClients = new List<PendingClient>();

        public PendingClientsManager() { }

        public bool AddPendingClient(int UserID, int CharacterID, string UID, int MapID, int Instance, int MapX, int MapY, bool IsTransfer)
        {
            lock (pendingClients)
            {
                RemovePendingClient(UserID);

                PendingClient pendingClient = new PendingClient(UserID, CharacterID, UID, MapID, Instance, MapX, MapY, IsTransfer);
                pendingClients.Add(pendingClient);
            }
            return true;
        }
        public PendingClient GetPendingClient(int UserID)
        {
            lock (pendingClients)
            {
                foreach (PendingClient pendingClient in pendingClients)
                {
                    if (pendingClient.userID == UserID)
                        return pendingClient;
                }
            }
            return null;
        }
        public bool RemovePendingClient(PendingClient pendingClient)
        {
            lock (pendingClients)
            {
                pendingClient.killTimeout();
                return pendingClients.Remove(pendingClient);
            }
        }
        public PendingClient RemovePendingClient(int UserID)
        {
            lock (pendingClients)
            {
                foreach (PendingClient pendingClient in pendingClients)
                {
                    if (pendingClient.userID == UserID)
                    {
                        pendingClients.Remove(pendingClient);
                        return pendingClient;
                    }
                }
            }
            return null;
        }
        public bool clientExists(int UserID)
        {
            lock (pendingClients)
            {
                foreach (PendingClient pendingClient in pendingClients)
                {
                    if (pendingClient.userID == UserID)
                        return true;
                }
            }
            return false;
        }
        
    }
}
